<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
	<meta http-equiv="expires" content="-1">
	<title> InfoHub - signin</title>
	<link rel="shortcut icon" href="sg/images/comverse.ico">
	<link rel="stylesheet" type="text/css" media="print" href="sg/skins/default/print.css">
	<link rel="stylesheet" type="text/css" media="screen" href="sg/skins/screen.en.css">
	<link rel="stylesheet" type="text/css" media="screen" href="sg/skins/narrow.css" title="Narrow">
	<link rel="alternate stylesheet" type="text/css" media="screen" href="sg/skins/normal.css" title="Normal">
	<link rel="alternate stylesheet" type="text/css" media="screen" href="sg/skins/wide.css" title="Wide">
	<link rel="stylesheet" type="text/css" media="screen" href="skins/sg.css">

	<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
	<script src="sg/script/yui/yahoo-dom-event/yahoo-dom-event.js" type="text/javascript"></script>  
  	<script src="sg/script/comverse/comverse.js" type="text/javascript"></script>
  	<script src="sg/script/comverse/style-switch.js" type="text/javascript"></script>
  	
  	<script>  		
		jQuery(document).ready( function() {
			jQuery("#import_button").click(function(){
				var emails = {"emails":jQuery("#login_original").val()};
				jQuery.ajax(
								{
									url:"importEmails.action", 
			    					data:emails,
					    			success:function(data, status){
					    				//alert("Data: " + data.toString() + "\nStatus: " + status);
					    				if(status === "success") {
					    					if(data.status) {
					    						var imported = data.importedEmails, failed=data.failedEmails;
					    						
					    						var importedStr="";
					    						for(x in imported) {
					    							importedStr = importedStr+imported[x]+"<br>";
					    						}
					    						
					    						var failedStr="failed:<br>";
					    						for(x in failed) {
					    							failedStr = failedStr + failed[x].email+":["+failed[x].reason+"]<br>";
					    						}
					    						
					    						jQuery("#result_body").html(importedStr);
					    						jQuery("#import_log").html(failedStr);
					    						
					    					} else {
					    						alert("failed to import, reason: "+data.reason);
					    					}
					    				}
					    			},
					    			type:"post",
					    			dataType:"json"
					    		}
			    );
			 });
		});		
	</script>
</head>

<#assign navtag="import">

<body class="cf010" id="home">

<div id="wrap">
	<div id="header">
		<#include "template/header.ftl">
	</div>
	<div id="nav" class="menu">
		<#include "template/menu.ftl">
	</div>
	<div id="main-body">
		<div id="content">
			<div class="col main">
				<div class="bread-crumbs">
					<h1></h1>
					<h2></h2>
					<div id="main-area">	
						<div id="import">	
									<table>
										<tbody>
											<tr>
												<td width="50%">
													<div class="result_header">Source:</div>
													<button id="import_button" type="button">import &rsaquo;&rsaquo;</button>
												</td>
												<td>
													<div class="result_body_header">Result:</div>
												</td>
											</tr>
											<tr>
												<td>
													<textarea id="login_original" name="original"></textarea>
												</td>
												<td>
													<div id="result_body"></div>
												</td>
											</tr>
										</tbody>
									</table>
							<div id="import_log"></div>
						</div>
					</div>
				</div>
			</div>
		</div>
		
		<div id="utilities">
			<#include "template/tools.ftl">
		</div> 
	</div>
	
	<div id="footer">
		<#include "template/footer.ftl">
	</div>

</div>
</body>
</html>